QByteArray 类

您所在的位置:网站首页 qbytearray left函数 QByteArray 类

QByteArray 类

2024-07-14 16:12| 来源: 网络整理| 查看: 265

QByteArray 类

QByteArray 类提供字节数组。 更多...

头: #include qmake: QT += core 所有成员列表,包括继承成员 过时成员

注意: 此类的所有函数 可重入 .

公共类型 class FromBase64Result enum Base64Option { Base64Encoding, Base64UrlEncoding, KeepTrailingEquals, OmitTrailingEquals, IgnoreBase64DecodingErrors, AbortOnBase64DecodingErrors } flags Base64Options typedef const_iterator typedef const_reverse_iterator typedef iterator typedef reverse_iterator 公共函数   QByteArray (QByteArray && other )   QByteArray (const QByteArray & other )   QByteArray (int size , char ch )   QByteArray (const char * data , int size = -1)   QByteArray () QByteArray & operator= (QByteArray && other ) QByteArray & operator= (const QByteArray & other )   ~QByteArray () QByteArray & append (const QByteArray & ba ) QByteArray & append (char ch ) QByteArray & append (int count , char ch ) QByteArray & append (const char * str ) QByteArray & append (const char * str , int len ) char at (int i ) const char back () const QByteRef back () QByteArray::iterator begin () QByteArray::const_iterator begin () const int capacity () const QByteArray::const_iterator cbegin () const QByteArray::const_iterator cend () const void chop (int n ) QByteArray chopped (int len ) const void clear () int compare (const char * c , Qt::CaseSensitivity cs = Qt::CaseSensitive) const int compare (const QByteArray & a , Qt::CaseSensitivity cs = Qt::CaseSensitive) const QByteArray::const_iterator constBegin () const const char * constData () const QByteArray::const_iterator constEnd () const bool contains (const QByteArray & ba ) const bool contains (char ch ) const bool contains (const char * str ) const int count (const QByteArray & ba ) const int count (char ch ) const int count (const char * str ) const int count () const QByteArray::const_reverse_iterator crbegin () const QByteArray::const_reverse_iterator crend () const char * data () const char * data () const QByteArray::iterator end () QByteArray::const_iterator end () const bool endsWith (const QByteArray & ba ) const bool endsWith (char ch ) const bool endsWith (const char * str ) const QByteArray & fill (char ch , int size = -1) char front () const QByteRef front () int indexOf (const QByteArray & ba , int from = 0) const int indexOf (char ch , int from = 0) const int indexOf (const char * str , int from = 0) const QByteArray & insert (int i , const QByteArray & ba ) QByteArray & insert (int i , char ch ) QByteArray & insert (int i , int count , char ch ) QByteArray & insert (int i , const char * str ) QByteArray & insert (int i , const char * str , int len ) bool isEmpty () const bool isLower () const bool isNull () const bool isUpper () const int lastIndexOf (const QByteArray & ba , int from = -1) const int lastIndexOf (char ch , int from = -1) const int lastIndexOf (const char * str , int from = -1) const QByteArray left (int len ) const QByteArray leftJustified (int width , char fill = ' ', bool truncate = false) const int length () const QByteArray mid (int pos , int len = -1) const QByteArray & prepend (const QByteArray & ba ) QByteArray & prepend (char ch ) QByteArray & prepend (int count , char ch ) QByteArray & prepend (const char * str ) QByteArray & prepend (const char * str , int len ) void push_back (const QByteArray & other ) void push_back (char ch ) void push_back (const char * str ) void push_front (const QByteArray & other ) void push_front (char ch ) void push_front (const char * str ) QByteArray::reverse_iterator rbegin () QByteArray::const_reverse_iterator rbegin () const QByteArray & remove (int pos , int len ) QByteArray::reverse_iterator rend () QByteArray::const_reverse_iterator rend () const QByteArray repeated (int times ) const QByteArray & replace (int pos , int len , const QByteArray & after ) QByteArray & replace (int pos , int len , const char * after ) QByteArray & replace (int pos , int len , const char * after , int alen ) QByteArray & replace (char before , const char * after ) QByteArray & replace (char before , const QByteArray & after ) QByteArray & replace (const char * before , const char * after ) QByteArray & replace (const char * before , int bsize , const char * after , int asize ) QByteArray & replace (const QByteArray & before , const QByteArray & after ) QByteArray & replace (const QByteArray & before , const char * after ) QByteArray & replace (const char * before , const QByteArray & after ) QByteArray & replace (char before , char after ) void reserve (int size ) void resize (int size ) QByteArray right (int len ) const QByteArray rightJustified (int width , char fill = ' ', bool truncate = false) const QByteArray & setNum (int n , int base = 10) QByteArray & setNum (short n , int base = 10) QByteArray & setNum (ushort n , int base = 10) QByteArray & setNum (uint n , int base = 10) QByteArray & setNum (qlonglong n , int base = 10) QByteArray & setNum (qulonglong n , int base = 10) QByteArray & setNum (float n , char f = 'g', int prec = 6) QByteArray & setNum (double n , char f = 'g', int prec = 6) QByteArray & setRawData (const char * data , uint size ) void shrink_to_fit () QByteArray simplified () const int size () const QList split (char sep ) const void squeeze () bool startsWith (const QByteArray & ba ) const bool startsWith (char ch ) const bool startsWith (const char * str ) const void swap (QByteArray & other ) QByteArray toBase64 () const QByteArray toBase64 (QByteArray::Base64Options options ) const CFDataRef toCFData () const double toDouble (bool * ok = nullptr) const float toFloat (bool * ok = nullptr) const QByteArray toHex () const QByteArray toHex (char separator ) const int toInt (bool * ok = nullptr, int base = 10) const long toLong (bool * ok = nullptr, int base = 10) const qlonglong toLongLong (bool * ok = nullptr, int base = 10) const QByteArray toLower () const NSData * toNSData () const QByteArray toPercentEncoding (const QByteArray & exclude = QByteArray(), const QByteArray & include = QByteArray(), char percent = '%') const CFDataRef toRawCFData () const NSData * toRawNSData () const short toShort (bool * ok = nullptr, int base = 10) const std::string toStdString () const uint toUInt (bool * ok = nullptr, int base = 10) const ulong toULong (bool * ok = nullptr, int base = 10) const qulonglong toULongLong (bool * ok = nullptr, int base = 10) const ushort toUShort (bool * ok = nullptr, int base = 10) const QByteArray toUpper () const QByteArray trimmed () const void truncate (int pos ) const char * operator const char * () const const void * operator const void * () const bool operator!= (const QString & str ) const QByteArray & operator+= (const QByteArray & ba ) QByteArray & operator+= (char ch ) QByteArray & operator+= (const char * str ) bool operator< (const QString & str ) const bool operator (const QString & str ) const bool operator>= (const QString & str ) const QByteRef operator[] (int i ) char operator[] (int i ) const char operator[] (uint i ) const QByteRef operator[] (uint i ) 静态公共成员 QByteArray fromBase64 (const QByteArray & base64 , QByteArray::Base64Options options ) QByteArray fromBase64 (const QByteArray & base64 ) QByteArray::FromBase64Result fromBase64Encoding (QByteArray && base64 , QByteArray::Base64Options options = Base64Encoding) QByteArray::FromBase64Result fromBase64Encoding (const QByteArray & base64 , QByteArray::Base64Options options = Base64Encoding) QByteArray fromCFData (CFDataRef data ) QByteArray fromHex (const QByteArray & hexEncoded ) QByteArray fromNSData (const NSData * data ) QByteArray fromPercentEncoding (const QByteArray & input , char percent = '%') QByteArray fromRawCFData (CFDataRef data ) QByteArray fromRawData (const char * data , int size ) QByteArray fromRawNSData (const NSData * data ) QByteArray fromStdString (const std::string & str ) QByteArray number (int n , int base = 10) QByteArray number (uint n , int base = 10) QByteArray number (qlonglong n , int base = 10) QByteArray number (qulonglong n , int base = 10) QByteArray number (double n , char f = 'g', int prec = 6) 相关非成员 quint16 qChecksum (const char * data , uint len ) quint16 qChecksum (const char * data , uint len , Qt::ChecksumType standard ) QByteArray qCompress (const QByteArray & data , int compressionLevel = -1) QByteArray qCompress (const uchar * data , int nbytes , int compressionLevel = -1) QByteArray qUncompress (const QByteArray & data ) QByteArray qUncompress (const uchar * data , int nbytes ) int qsnprintf (char * str , size_t n , const char * fmt , ... ) int qstrcmp (const char * str1 , const char * str2 ) char * qstrcpy (char * dst , const char * src ) char * qstrdup (const char * src ) int qstricmp (const char * str1 , const char * str2 ) uint qstrlen (const char * str ) int qstrncmp (const char * str1 , const char * str2 , uint len ) char * qstrncpy (char * dst , const char * src , uint len ) int qstrnicmp (const char * str1 , const char * str2 , uint len ) uint qstrnlen (const char * str , uint maxlen ) int qvsnprintf (char * str , size_t n , const char * fmt , va_list ap ) bool operator!= (const QByteArray & a1 , const QByteArray & a2 ) bool operator!= (const QByteArray & a1 , const char * a2 ) bool operator!= (const char * a1 , const QByteArray & a2 ) const QByteArray operator+ (const QByteArray & a1 , const QByteArray & a2 ) const QByteArray operator+ (const QByteArray & a1 , const char * a2 ) const QByteArray operator+ (const QByteArray & a1 , char a2 ) const QByteArray operator+ (const char * a1 , const QByteArray & a2 ) const QByteArray operator+ (char a1 , const QByteArray & a2 ) bool operator< (const QByteArray & a1 , const QByteArray & a2 ) bool operator< (const QByteArray & a1 , const char * a2 ) bool operator< (const char * a1 , const QByteArray & a2 ) QDataStream & operator= (const QByteArray & a1 , const QByteArray & a2 ) bool operator>= (const QByteArray & a1 , const char * a2 ) bool operator>= (const char * a1 , const QByteArray & a2 ) QDataStream & operator>> (QDataStream & in , QByteArray & ba ) 宏   QByteArrayLiteral ( ba )   QT_NO_CAST_FROM_BYTEARRAY 详细描述

QByteArray 可以被用于存储原生字节 (包括 \0) 和传统 8 位以 \0 结尾的字符串。使用 QByteArray 更方便比使用 const char * 。在幕后,它始终确保数据之后紧跟 \0 终止符,并使用 隐式共享 (写入时拷贝) 以缩减内存使用量和避免不必要的数据拷贝。

除 QByteArray 外,Qt 还提供 QString 类以存储字符串数据。对于大多数目的, QString 是您想要使用的类。它存储 16 位 Unicode 字符,使之能在应用程序中轻松存储非 ASCII 和非 Latin-1 字符。此外, QString is used throughout in the Qt API. The two main cases where QByteArray is appropriate are when you need to store raw binary data, and when memory conservation is critical (e.g., with Qt for Embedded Linux).

One way to initialize a QByteArray is simply to pass a const char * 到其构造函数。例如,以下代码创建包含数据 Hello 大小为 5 的字节数组:

QByteArray ba("Hello");

尽管 size () is 5, the byte array also maintains an extra '\0' character at the end so that if a function is used that asks for a pointer to the underlying data (e.g. a call to data ()), the data pointed to is guaranteed to be '\0'-terminated.

QByteArray makes a deep copy of the const char * data, so you can modify it later without experiencing side effects. (If for performance reasons you don't want to take a deep copy of the character data, use QByteArray::fromRawData () instead.)

Another approach is to set the size of the array using resize () and to initialize the data byte per byte. QByteArray uses 0-based indexes, just like C++ arrays. To access the byte at a particular index position, you can use operator[](). On non-const byte arrays, operator[]() returns a reference to a byte that can be used on the left side of an assignment. For example:

QByteArray ba; ba.resize(5); ba[0] = 0x3c; ba[1] = 0xb8; ba[2] = 0x64; ba[3] = 0x18; ba[4] = 0xca;

For read-only access, an alternative syntax is to use at ():

for (int i = 0; i = 'a' && ba.at(i) = size (), returns a byte array containing all bytes starting at position pos until the end of the byte array.

范例:

QByteArray x("Five pineapples"); QByteArray y = x.mid(5, 4); // y == "pine" QByteArray z = x.mid(5); // z == "pineapples"

另请参阅 left (), right (), chopped (), chop (),和 truncate ().

[static] QByteArray QByteArray:: number ( int n , int base = 10)

Returns a byte array containing the string equivalent of the number n to base base (10 by default). The base can be any value between 2 and 36.

范例:

int n = 63; QByteArray::number(n); // returns "63" QByteArray::number(n, 16); // returns "3f" QByteArray::number(n, 16).toUpper(); // returns "3F"

注意: The format of the number is not localized; the default C locale is used irrespective of the user's locale.

另请参阅 setNum () 和 toInt ().

[static] QByteArray QByteArray:: number ( uint n , int base = 10)

这是重载函数。

另请参阅 toUInt ().

[static] QByteArray QByteArray:: number ( qlonglong n , int base = 10)

这是重载函数。

另请参阅 toLongLong ().

[static] QByteArray QByteArray:: number ( qulonglong n , int base = 10)

这是重载函数。

另请参阅 toULongLong ().

[static] QByteArray QByteArray:: number ( double n , char f = 'g', int prec = 6)

这是重载函数。

Returns a byte array that contains the printed value of n , formatted in format f with precision prec .

Argument n is formatted according to the f format specified, which is g by default, and can be any of the following:

格式 含义 e format as [-]9.9e[+|-]999 E format as [-]9.9E[+|-]999 f format as [-]9.9 g 使用 e or f format, whichever is the most concise G 使用 E or f format, whichever is the most concise

With 'e', 'E', and 'f', prec is the number of digits after the decimal point. With 'g' and 'G', prec is the maximum number of significant digits (trailing zeroes are omitted).

QByteArray ba = QByteArray::number(12.3456, 'E', 3); // ba == 1.235E+01

注意: The format of the number is not localized; the default C locale is used irrespective of the user's locale.

另请参阅 toDouble ().

QByteArray &QByteArray:: prepend (const QByteArray & ba )

前置字节数组 ba 到此字节数组,并返回此字节数组的引用。

范例:

QByteArray x("ship"); QByteArray y("air"); x.prepend(y); // x == "airship"

这如同 insert(0, ba ).

注意: QByteArray 是 隐式共享 class. Consequently, if you prepend to an empty byte array, then the byte array will just share the data held in ba 。在这种情况下,不进行数据拷贝,花费 常量时间 。若共享实例被修改,它将被拷贝 (写时拷贝),花费 线性时间 .

If the byte array being prepended to is not empty, a deep copy of the data is performed, taking 线性时间 .

另请参阅 append () 和 insert ().

QByteArray &QByteArray:: prepend ( char ch )

这是重载函数。

前置字符 ch 到此字节数组。

QByteArray &QByteArray:: prepend ( int count , char ch )

这是重载函数。

前置 count copies of character ch 到此字节数组。

该函数在 Qt 5.7 引入。

QByteArray &QByteArray:: prepend (const char * str )

这是重载函数。

前置字符串 str 到此字节数组。

QByteArray &QByteArray:: prepend (const char * str , int len )

这是重载函数。

前置 len bytes of the string str 到此字节数组。

该函数在 Qt 4.6 引入。

void QByteArray:: push_back (const QByteArray & other )

This function is provided for STL compatibility. It is equivalent to append( other ).

void QByteArray:: push_back ( char ch )

这是重载函数。

如同 append( ch ).

void QByteArray:: push_back (const char * str )

这是重载函数。

如同 append( str ).

void QByteArray:: push_front (const QByteArray & other )

This function is provided for STL compatibility. It is equivalent to prepend( other ).

void QByteArray:: push_front ( char ch )

这是重载函数。

如同 prepend( ch ).

void QByteArray:: push_front (const char * str )

这是重载函数。

如同 prepend( str ).

QByteArray::reverse_iterator QByteArray:: rbegin ()

返回 STL-style reverse iterator pointing to the first character in the byte-array, in reverse order.

该函数在 Qt 5.6 引入。

另请参阅 begin (), crbegin (),和 rend ().

QByteArray::const_reverse_iterator QByteArray:: rbegin () const

这是重载函数。

该函数在 Qt 5.6 引入。

QByteArray &QByteArray:: remove ( int pos , int len )

移除 len bytes from the array, starting at index position pos , and returns a reference to the array.

若 pos is out of range, nothing happens. If pos is valid, but pos + len is larger than the size of the array, the array is truncated at position pos .

范例:

QByteArray ba("Montreal"); ba.remove(1, 4); // ba == "Meal"

另请参阅 insert () 和 replace ().

QByteArray::reverse_iterator QByteArray:: rend ()

返回 STL-style reverse iterator pointing to one past the last character in the byte-array, in reverse order.

该函数在 Qt 5.6 引入。

另请参阅 end (), crend (),和 rbegin ().

QByteArray::const_reverse_iterator QByteArray:: rend () const

这是重载函数。

该函数在 Qt 5.6 引入。

QByteArray QByteArray:: repeated ( int times ) const

Returns a copy of this byte array repeated the specified number of times .

若 times is less than 1, an empty byte array is returned.

范例:

QByteArray ba("ab"); ba.repeated(4); // returns "abababab"

该函数在 Qt 4.5 引入。

QByteArray &QByteArray:: replace ( int pos , int len , const QByteArray & after )

替换 len bytes from index position pos with the byte array after , and returns a reference to this byte array.

范例:

QByteArray x("Say yes!"); QByteArray y("no"); x.replace(4, 3, y); // x == "Say no!"

另请参阅 insert () 和 remove ().

QByteArray &QByteArray:: replace ( int pos , int len , const char * after )

这是重载函数。

替换 len bytes from index position pos with the '\0'-terminated string after .

注意:这可以改变字节数组的长度。

QByteArray &QByteArray:: replace ( int pos , int len , const char * after , int alen )

这是重载函数。

替换 len bytes from index position pos with alen bytes from the string after . after is allowed to have '\0' characters.

该函数在 Qt 4.7 引入。

QByteArray &QByteArray:: replace ( char before , const char * after )

这是重载函数。

Replaces every occurrence of the character before 采用字符串 after .

QByteArray &QByteArray:: replace ( char before , const QByteArray & after )

这是重载函数。

Replaces every occurrence of the character before with the byte array after .

QByteArray &QByteArray:: replace (const char * before , const char * after )

这是重载函数。

Replaces every occurrence of the string before 采用字符串 after .

QByteArray &QByteArray:: replace (const char * before , int bsize , const char * after , int asize )

这是重载函数。

Replaces every occurrence of the string before 采用字符串 after . Since the sizes of the strings are given by bsize and asize , they may contain zero characters and do not need to be '\0'-terminated.

QByteArray &QByteArray:: replace (const QByteArray & before , const QByteArray & after )

这是重载函数。

Replaces every occurrence of the byte array before with the byte array after .

范例:

QByteArray ba("colour behaviour flavour neighbour"); ba.replace(QByteArray("ou"), QByteArray("o")); // ba == "color behavior flavor neighbor" QByteArray &QByteArray:: replace (const QByteArray & before , const char * after )

这是重载函数。

Replaces every occurrence of the byte array before 采用字符串 after .

QByteArray &QByteArray:: replace (const char * before , const QByteArray & after )

这是重载函数。

Replaces every occurrence of the string before with the byte array after .

QByteArray &QByteArray:: replace ( char before , char after )

这是重载函数。

Replaces every occurrence of the character before with the character after .

void QByteArray:: reserve ( int size )

试图分配内存为至少 size bytes. If you know in advance how large the byte array will be, you can call this function, and if you call resize () often you are likely to get better performance. If size is an underestimate, the worst that will happen is that the QByteArray will be a bit slower.

The sole purpose of this function is to provide a means of fine tuning QByteArray 's memory usage. In general, you will rarely ever need to call this function. If you want to change the size of the byte array, call resize ().

另请参阅 squeeze () 和 capacity ().

void QByteArray:: resize ( int size )

把字节数组的尺寸设为 size 字节。

若 size is greater than the current size, the byte array is extended to make it size bytes with the extra bytes added to the end. The new bytes are uninitialized.

若 size is less than the current size, bytes are removed from the end.

另请参阅 size () 和 truncate ().

QByteArray QByteArray:: right ( int len ) const

返回的字节数组包含最右 len 字节在此字节数组。

返回整个字节数组若 len 大于 size ().

范例:

QByteArray x("Pineapple"); QByteArray y = x.right(5); // y == "apple"

另请参阅 endsWith (), left (), mid (), chopped (), chop (),和 truncate ().

QByteArray QByteArray:: rightJustified ( int width , char fill = ' ', bool truncate = false) const

Returns a byte array of size width 包含 fill character followed by this byte array.

若 truncate is false and the size of the byte array is more than width , then the returned byte array is a copy of this byte array.

若 truncate is true and the size of the byte array is more than width , then the resulting byte array is truncated at position width .

范例:

QByteArray x("apple"); QByteArray y = x.rightJustified(8, '.'); // y == "...apple"

另请参阅 leftJustified ().

QByteArray &QByteArray:: setNum ( int n , int base = 10)

Sets the byte array to the printed value of n in base base (10 by default) and returns a reference to the byte array. The base can be any value between 2 and 36. For bases other than 10, n is treated as an unsigned integer.

范例:

QByteArray ba; int n = 63; ba.setNum(n); // ba == "63" ba.setNum(n, 16); // ba == "3f"

注意: The format of the number is not localized; the default C locale is used irrespective of the user's locale.

另请参阅 number () 和 toInt ().

QByteArray &QByteArray:: setNum ( short n , int base = 10)

这是重载函数。

另请参阅 toShort ().

QByteArray &QByteArray:: setNum ( ushort n , int base = 10)

这是重载函数。

另请参阅 toUShort ().

QByteArray &QByteArray:: setNum ( uint n , int base = 10)

这是重载函数。

另请参阅 toUInt ().

QByteArray &QByteArray:: setNum ( qlonglong n , int base = 10)

这是重载函数。

另请参阅 toLongLong ().

QByteArray &QByteArray:: setNum ( qulonglong n , int base = 10)

这是重载函数。

另请参阅 toULongLong ().

QByteArray &QByteArray:: setNum ( float n , char f = 'g', int prec = 6)

这是重载函数。

Sets the byte array to the printed value of n , formatted in format f with precision prec , and returns a reference to the byte array.

注意: The format of the number is not localized; the default C locale is used irrespective of the user's locale.

另请参阅 toFloat ().

QByteArray &QByteArray:: setNum ( double n , char f = 'g', int prec = 6)

这是重载函数。

Sets the byte array to the printed value of n , formatted in format f with precision prec , and returns a reference to the byte array.

格式 f 可以是下列任一:

格式 含义 e format as [-]9.9e[+|-]999 E format as [-]9.9E[+|-]999 f format as [-]9.9 g 使用 e or f format, whichever is the most concise G 使用 E or f format, whichever is the most concise

With 'e', 'E', and 'f', prec is the number of digits after the decimal point. With 'g' and 'G', prec is the maximum number of significant digits (trailing zeroes are omitted).

注意: The format of the number is not localized; the default C locale is used irrespective of the user's locale.

另请参阅 toDouble ().

QByteArray &QByteArray:: setRawData (const char * data , uint size )

Resets the QByteArray to use the first size bytes of the data array. The bytes are not copied. The QByteArray will contain the data pointer. The caller guarantees that data will not be deleted or modified as long as this QByteArray and any copies of it exist that have not been modified.

This function can be used instead of fromRawData () to re-use existing QByteArray objects to save memory re-allocations.

该函数在 Qt 4.7 引入。

另请参阅 fromRawData (), data (),和 constData ().

void QByteArray:: shrink_to_fit ()

提供此函数是为兼容 STL。它相当于 squeeze ().

该函数在 Qt 5.10 引入。

QByteArray QByteArray:: simplified () const

Returns a byte array that has whitespace removed from the start and the end, and which has each sequence of internal whitespace replaced with a single space.

Whitespace means any character for which the standard C++ isspace() 函数返回 true in the C locale. This includes the ASCII isspace() function returns true in the C locale. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

范例:

QByteArray ba(" lots\t of\nwhitespace\r\n "); ba = ba.simplified(); // ba == "lots of whitespace";

另请参阅 trimmed ().

int QByteArray:: size () const

返回此字节数组的字节数。

The last byte in the byte array is at position size() - 1. In addition, QByteArray ensures that the byte at position size() is always '\0', so that you can use the return value of data () 和 constData () as arguments to functions that expect '\0'-terminated strings. If the QByteArray object was created from a raw data that didn't include the trailing null-termination character then QByteArray doesn't add it automaticall unless the 深拷贝 is created.

范例:

QByteArray ba("Hello"); int n = ba.size(); // n == 5 ba.data()[0]; // returns 'H' ba.data()[4]; // returns 'o' ba.data()[5]; // returns '\0'

另请参阅 isEmpty () 和 resize ().

QList < QByteArray > QByteArray:: split ( char sep ) const

Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays. If sep does not match anywhere in the byte array, split() returns a single-element list containing this byte array.

void QByteArray:: squeeze ()

Releases any memory not required to store the array's data.

The sole purpose of this function is to provide a means of fine tuning QByteArray 's memory usage. In general, you will rarely ever need to call this function.

另请参阅 reserve () 和 capacity ().

bool QByteArray:: startsWith (const QByteArray & ba ) const

返回 true 若此字节数组的开头是字节数组 ba ;否则返回 false .

范例:

QByteArray url("ftp://ftp.qt-project.org/"); if (url.startsWith("ftp:")) ...

另请参阅 endsWith () 和 left ().

bool QByteArray:: startsWith ( char ch ) const

这是重载函数。

返回 true if this byte array starts with character ch ;否则返回 false .

bool QByteArray:: startsWith (const char * str ) const

这是重载函数。

返回 true if this byte array starts with string str ;否则返回 false .

void QByteArray:: swap ( QByteArray & other )

Swaps byte array other with this byte array. This operation is very fast and never fails.

该函数在 Qt 4.8 引入。

QByteArray QByteArray:: toBase64 () const

Returns a copy of the byte array, encoded as Base64.

QByteArray text("Qt is great!"); text.toBase64(); // returns "UXQgaXMgZ3JlYXQh"

The algorithm used to encode Base64-encoded data is defined in RFC 4648 .

另请参阅 fromBase64 ().

QByteArray QByteArray:: toBase64 ( QByteArray::Base64Options options ) const

这是重载函数。

Returns a copy of the byte array, encoded using the options options .

QByteArray text("

Hello?

"); text.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals); // returns "PHA+SGVsbG8/PC9wPg" text.toBase64(QByteArray::Base64Encoding); // returns "PHA+SGVsbG8/PC9wPg==" text.toBase64(QByteArray::Base64UrlEncoding); // returns "PHA-SGVsbG8_PC9wPg==" text.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); // returns "PHA-SGVsbG8_PC9wPg"

The algorithm used to encode Base64-encoded data is defined in RFC 4648 .

该函数在 Qt 5.2 引入。

另请参阅 fromBase64 ().

CFDataRef QByteArray:: toCFData () const

创建 CFData 从 QByteArray . The caller owns the CFData object and is responsible for releasing it.

该函数在 Qt 5.3 引入。

另请参阅 toRawCFData (), fromCFData (), fromRawCFData (),和 fromRawData ().

double QByteArray:: toDouble ( bool * ok = nullptr) const

Returns the byte array converted to a double 值。

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

QByteArray string("1234.56"); bool ok; double a = string.toDouble(&ok); // a == 1234.56, ok == true string = "1234.56 Volt"; a = str.toDouble(&ok); // a == 0, ok == false

警告: QByteArray content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

此函数忽略前导和结尾空格。

另请参阅 number ().

float QByteArray:: toFloat ( bool * ok = nullptr) const

Returns the byte array converted to a float 值。

Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

QByteArray string("1234.56"); bool ok; float a = string.toFloat(&ok); // a == 1234.56, ok == true string = "1234.56 Volt"; a = str.toFloat(&ok); // a == 0, ok == false

警告: QByteArray content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

此函数忽略前导和结尾空格。

另请参阅 number ().

QByteArray QByteArray:: toHex () const

Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.

另请参阅 fromHex ().

QByteArray QByteArray:: toHex ( char separator ) const

这是重载函数。

Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.

若 separator is not '\0', the separator character is inserted between the hex bytes.

范例:

QByteArray macAddress = QByteArray::fromHex("123456abcdef"); macAddress.toHex(':'); // returns "12:34:56:ab:cd:ef" macAddress.toHex(0); // returns "123456abcdef"

该函数在 Qt 5.9 引入。

另请参阅 fromHex ().

int QByteArray:: toInt ( bool * ok = nullptr, int base = 10) const

Returns the byte array converted to an int using base base , which is 10 by default and must be between 2 and 36, or 0.

若 base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

返回 0,若转换失败。

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

QByteArray str("FF"); bool ok; int hex = str.toInt(&ok, 16); // hex == 255, ok == true int dec = str.toInt(&ok, 10); // dec == 0, ok == false

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

另请参阅 number ().

long QByteArray:: toLong ( bool * ok = nullptr, int base = 10) const

Returns the byte array converted to a long int using base base , which is 10 by default and must be between 2 and 36, or 0.

若 base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

返回 0,若转换失败。

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

QByteArray str("FF"); bool ok; long hex = str.toLong(&ok, 16); // hex == 255, ok == true long dec = str.toLong(&ok, 10); // dec == 0, ok == false

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

该函数在 Qt 4.1 引入。

另请参阅 number ().

qlonglong QByteArray:: toLongLong ( bool * ok = nullptr, int base = 10) const

Returns the byte array converted to a long long using base base , which is 10 by default and must be between 2 and 36, or 0.

若 base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

返回 0,若转换失败。

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

另请参阅 number ().

QByteArray QByteArray:: toLower () const

Returns a lowercase copy of the byte array. The bytearray is interpreted as a Latin-1 encoded string.

范例:

QByteArray x("Qt by THE QT COMPANY"); QByteArray y = x.toLower(); // y == "qt by the qt company"

另请参阅 isLower (), toUpper (),和 8 位字符比较 .

NSData *QByteArray:: toNSData () const

创建 NSData 从 QByteArray . The NSData object is autoreleased.

该函数在 Qt 5.3 引入。

另请参阅 fromNSData (), fromRawNSData (), fromRawData (),和 toRawNSData ().

QByteArray QByteArray:: toPercentEncoding (const QByteArray & exclude = QByteArray(), const QByteArray & include = QByteArray(), char percent = '%') const

Returns a URI/URL-style percent-encoded copy of this byte array. The percent parameter allows you to override the default '%' character for another.

By default, this function will encode all characters that are not one of the following:

ALPHA ("a" to "z" and "A" to "Z") / DIGIT (0 to 9) / "-" / "." / "_" / "~"

To prevent characters from being encoded pass them to exclude . To force characters to be encoded pass them to include 。 percent character is always encoded.

范例:

QByteArray text = "{a fishy string?}"; QByteArray ba = text.toPercentEncoding("{}", "s"); qDebug(ba.constData()); // prints "{a fi%73hy %73tring%3F}"

The hex encoding uses the numbers 0-9 and the uppercase letters A-F.

该函数在 Qt 4.4 引入。

另请参阅 fromPercentEncoding () 和 QUrl::toPercentEncoding ().

CFDataRef QByteArray:: toRawCFData () const

Constructs a CFData that uses the bytes of the QByteArray .

QByteArray 的字节不拷贝。

The caller guarantees that the QByteArray will not be deleted or modified as long as this CFData object exists.

该函数在 Qt 5.3 引入。

另请参阅 toCFData (), fromRawCFData (), fromCFData (),和 fromRawData ().

NSData *QByteArray:: toRawNSData () const

Constructs a NSData that uses the bytes of the QByteArray .

QByteArray 的字节不拷贝。

The caller guarantees that the QByteArray will not be deleted or modified as long as this NSData object exists.

该函数在 Qt 5.3 引入。

另请参阅 fromRawNSData (), fromNSData (), fromRawData (),和 toNSData ().

short QByteArray:: toShort ( bool * ok = nullptr, int base = 10) const

Returns the byte array converted to a short using base base , which is 10 by default and must be between 2 and 36, or 0.

若 base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

返回 0,若转换失败。

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

另请参阅 number ().

std::string QByteArray:: toStdString () const

Returns a std::string object with the data contained in this QByteArray .

This operator is mostly useful to pass a QByteArray to a function that accepts a std::string object.

该函数在 Qt 5.4 引入。

另请参阅 fromStdString () 和 QString::toStdString ().

uint QByteArray:: toUInt ( bool * ok = nullptr, int base = 10) const

Returns the byte array converted to an 无符号 int using base base , which is 10 by default and must be between 2 and 36, or 0.

若 base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

返回 0,若转换失败。

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

另请参阅 number ().

ulong QByteArray:: toULong ( bool * ok = nullptr, int base = 10) const

Returns the byte array converted to an unsigned long int using base base , which is 10 by default and must be between 2 and 36, or 0.

若 base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

返回 0,若转换失败。

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

该函数在 Qt 4.1 引入。

另请参阅 number ().

qulonglong QByteArray:: toULongLong ( bool * ok = nullptr, int base = 10) const

Returns the byte array converted to an unsigned long long using base base , which is 10 by default and must be between 2 and 36, or 0.

若 base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

返回 0,若转换失败。

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

另请参阅 number ().

ushort QByteArray:: toUShort ( bool * ok = nullptr, int base = 10) const

Returns the byte array converted to an unsigned short using base base , which is 10 by default and must be between 2 and 36, or 0.

若 base is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.

返回 0,若转换失败。

若 ok 不是 nullptr , failure is reported by setting * ok to false , and success by setting * ok to true .

注意: The conversion of the number is performed in the default C locale, irrespective of the user's locale.

另请参阅 number ().

QByteArray QByteArray:: toUpper () const

Returns an uppercase copy of the byte array. The bytearray is interpreted as a Latin-1 encoded string.

范例:

QByteArray x("Qt by THE QT COMPANY"); QByteArray y = x.toUpper(); // y == "QT BY THE QT COMPANY"

另请参阅 isUpper (), toLower (),和 8 位字符比较 .

QByteArray QByteArray:: trimmed () const

Returns a byte array that has whitespace removed from the start and the end.

Whitespace means any character for which the standard C++ isspace() 函数返回 true in the C locale. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

范例:

QByteArray ba(" lots\t of\nwhitespace\r\n "); ba = ba.trimmed(); // ba == "lots\t of\nwhitespace";

不像 simplified (), trimmed() leaves internal whitespace alone.

另请参阅 simplified ().

void QByteArray:: truncate ( int pos )

Truncates the byte array at index position pos .

若 pos is beyond the end of the array, nothing happens.

范例:

QByteArray ba("Stockholm"); ba.truncate(5); // ba == "Stock"

另请参阅 chop (), resize (),和 left ().

bool QByteArray:: operator!= (const QString & str ) const

返回 true if this byte array is not equal to string str ;否则返回 false .

The Unicode data is converted into 8-bit characters using QString::toUtf8 ().

比较是区分大小写的。

可以禁用此运算符通过定义 QT_NO_CAST_FROM_ASCII 当编译应用程序时。那么需要调用 QString::fromUtf8 (), QString::fromLatin1 (),或 QString::fromLocal8Bit () explicitly if you want to convert the byte array to a QString before doing the comparison.

QByteArray &QByteArray:: operator+= (const QByteArray & ba )

追加字节数组 ba onto the end of this byte array and returns a reference to this byte array.

范例:

QByteArray x("free"); QByteArray y("dom"); x += y; // x == "freedom"

注意: QByteArray 是 隐式共享 类。因此,若追加到空字节数组,那么字节数组将仅仅共享的数据保持在 ba 。在这种情况下,不进行数据拷贝,花费 常量时间 。若共享实例被修改,它将被拷贝 (写时拷贝),花费 线性时间 .

若要追加到的字节数组非空,履行数据深拷贝,花费 线性时间 .

This operation typically does not suffer from allocation overhead, because QByteArray preallocates extra space at the end of the data so that it may grow without reallocating for each append operation.

另请参阅 append () 和 prepend ().

QByteArray &QByteArray:: operator+= ( char ch )

这是重载函数。

追加字符 ch onto the end of this byte array and returns a reference to this byte array.

QByteArray &QByteArray:: operator+= (const char * str )

这是重载函数。

追加字符串 str onto the end of this byte array and returns a reference to this byte array.

bool QByteArray:: operator< (const QString & str ) const

返回 true if this byte array is lexically less than string str ;否则返回 false .

The Unicode data is converted into 8-bit characters using QString::toUtf8 ().

比较是区分大小写的。

可以禁用此运算符通过定义 QT_NO_CAST_FROM_ASCII 当编译应用程序时。那么需要调用 QString::fromUtf8 (), QString::fromLatin1 (),或 QString::fromLocal8Bit () explicitly if you want to convert the byte array to a QString before doing the comparison.

bool QByteArray:: operator (const QString & str ) const

返回 true if this byte array is lexically greater than string str ;否则返回 false .

The Unicode data is converted into 8-bit characters using QString::toUtf8 ().

比较是区分大小写的。

可以禁用此运算符通过定义 QT_NO_CAST_FROM_ASCII 当编译应用程序时。那么需要调用 QString::fromUtf8 (), QString::fromLatin1 (),或 QString::fromLocal8Bit () explicitly if you want to convert the byte array to a QString before doing the comparison.

bool QByteArray:: operator>= (const QString & str ) const

返回 true if this byte array is greater than or equal to string str ;否则返回 false .

The Unicode data is converted into 8-bit characters using QString::toUtf8 ().

比较是区分大小写的。

可以禁用此运算符通过定义 QT_NO_CAST_FROM_ASCII 当编译应用程序时。那么需要调用 QString::fromUtf8 (), QString::fromLatin1 (),或 QString::fromLocal8Bit () explicitly if you want to convert the byte array to a QString before doing the comparison.

QByteRef QByteArray:: operator[] ( int i )

Returns the byte at index position i as a modifiable reference.

If an assignment is made beyond the end of the byte array, the array is extended with resize () before the assignment takes place.

范例:

QByteArray ba("Hello, world"); cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3